//
//  SkeletonCollectionCell.swift
//  koolcar
//
//  Created by xiantian on 2023/12/4.
//

import UIKit
import SkeletonView
class SkeletonCollectionCell: UICollectionViewCell {
    var bgView: UIView = {
        let tempView = UIView()
        tempView.isSkeletonable = true
        return tempView
    }()
    var imgView: UIImageView = {
        let tempImgView = UIImageView()
        tempImgView.isSkeletonable = true
        return tempImgView
    }()
    var nameLab: UILabel = {
        let tempLab = UILabel()
        tempLab.textColor = Theme.titleLabColor
        tempLab.backgroundColor = UIColor.clear
        tempLab.font = UIFont.init(name: Theme.PingFangSCRegular, size: 14)
        tempLab.numberOfLines = 0
        tempLab.lineBreakMode = .byTruncatingTail
        tempLab.textAlignment = .left
        tempLab.isSkeletonable = true
        return tempLab
    }()
    var priceLab: UILabel = {
        let tempLab = UILabel()
        tempLab.textColor = Theme.titleLabColor
        tempLab.backgroundColor = UIColor.clear
        tempLab.font = UIFont.init(name: Theme.PingFangSCRegular, size: 14)
        tempLab.numberOfLines = 0
        tempLab.lineBreakMode = .byTruncatingTail
        tempLab.textAlignment = .left
        tempLab.isSkeletonable = true
        return tempLab
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.isSkeletonable = true
        self.contentView.addSubview(bgView)
        bgView.addSubview(imgView)
        bgView.addSubview(nameLab)
        bgView.addSubview(priceLab)
        
        self.addSnpLayout()
    }
    
    private func addSnpLayout(){
        self.bgView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        self.imgView.snp.makeConstraints { make in
            make.top.equalTo(0)
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.height.equalTo(112)
        }
        self.nameLab.snp.makeConstraints { make in
            make.top.equalTo(self.imgView.snp.bottom).offset(5)
            make.left.equalTo(8)
            make.right.equalTo(-8)
            make.height.greaterThanOrEqualTo(40)
        }
        
        self.priceLab.snp.makeConstraints { make in
            make.top.equalTo(self.nameLab.snp.bottom).offset(0)
            make.left.equalTo(8)
            make.right.equalTo(-8)
            make.height.greaterThanOrEqualTo(20)
        }
        self.layoutIfNeeded()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
